package cn.itcast.encapsulation;

public class Account {
    private String name;
    private double balance;
    private String pwd;

    public String getName() {
        return name;
    }

    /**
     * 姓名长度小于4
     * @param name
     */
    public void setName(String name) {
        if (name.length() <= 4){
            this.name = name;
        }else {
            System.out.println("name不合格,默认值为 无名氏");
            this.name = "无名";
        }
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        if (balance >= 20){
            this.balance = balance;
        }else {
            System.out.println("余额太少，默认为零");
        }
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        if (pwd.length() == 6){
            this.pwd = pwd;
        }else {
            System.out.println("密码必须是六位，初始化为六个零");
            this.pwd = "000000";
        }
    }

    public Account(String name, double balance, String pwd) {
        setName(name);
        setBalance(balance);
        setPwd(pwd);
    }

    public Account() {
    }
    public void show(){
        System.out.print("账号信息 name="+name+",余额"+ balance + ",密码="+pwd);
    }
}
